const express = require('express');
const session = require('express-session');
const bodyParser = require('body-parser');
const path = require('path');
const authRoutes = require('./routes/auth');
const dataRoutes = require('./routes/data');

const app = express();

// 中间件配置
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(session({
    secret: 'your_secret_key',
    resave: false,
    saveUninitialized: true,
}));
// 静态资源只指向公共资源目录，如静态文件
app.use('/static', express.static(path.join(__dirname, 'public'))); // 例如存放样式和脚本


// 路由
app.use('/auth', authRoutes);
app.use('/data', dataRoutes);

// 首页
app.get('/', (req, res) => {
    res.sendFile(path.join(__dirname, 'views', 'login.html'));
});

app.get('/res', (req, res) => {
    res.sendFile(path.join(__dirname, 'views', 'res.html'));
});




const PORT = 3000;
app.listen(PORT, () => {
    console.log(`Server running at http://localhost:${PORT}`);
});
